package com.appsl.manager;

import com.appsl.animations.ActivityAnimator;
import com.appsl.digitalparking.DetalleLugarActivity;
import com.appsl.digitalparking.FavMapActivity;
import com.appsl.digitalparking.Favourites;
import com.appsl.digitalparking.LoginActivity;
import com.appsl.digitalparking.LoginFB;
import com.appsl.digitalparking.LoginTW;
import com.appsl.digitalparking.LoginGP;
import com.appsl.digitalparking.MainAppView;
import com.appsl.digitalparking.Map;
import com.appsl.digitalparking.Parking_lot;
import com.appsl.digitalparking.PisoActivity;
import com.appsl.digitalparking.Presentation;
import com.appsl.digitalparking.SettingsActivity;

import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;

public class Redirection 
{	
	private static String[] _animationList = {"fade", "flipHorizontal", "flipVertical", "disappearTopLeft", "appearTopLeft", "appearBottomRight", "disappearBottomRight", "unzoom"};
	
	public static void goToMainAppView(Activity parent){
		Intent intent = new Intent(parent, MainAppView.class);
		intent.putExtra("backAnimation", _animationList[1]);
		parent.startActivity(intent);
		try
        {
                ActivityAnimator anim = new ActivityAnimator();
                anim.getClass().getMethod(_animationList[1] + "Animation", Activity.class).invoke(anim, parent);
        }
		catch (Exception e) { Toast.makeText(parent, "An error occured " + e.toString(), Toast.LENGTH_LONG).show(); }
		parent.finish();
	}
	
	public static void goToLoginAct(Activity login, String target){
		if (target.equals("Facebook")){
			Intent intent = new Intent(login, LoginFB.class);
			login.startActivity(intent);
			login.finish();
			return;
		}
		
		if (target.equals("Twitter")){
			Intent intent = new Intent(login, LoginTW.class);
			login.startActivity(intent);
			login.finish();
			return;
		}
		
		if (target.equals("Google Plus")){
			Intent intent = new Intent(login, LoginGP.class);
			login.startActivity(intent);
			login.finish();
			return;
		}
	}
		
	public static void goToLogin(Activity parent){
		Intent intent = new Intent(parent, LoginActivity.class);
		intent.putExtra("backAnimation", _animationList[2]);
		parent.startActivity(intent);
		try
        {
                ActivityAnimator anim = new ActivityAnimator();
                anim.getClass().getMethod(_animationList[2] + "Animation", Activity.class).invoke(anim, parent);
        }
		catch (Exception e) { Toast.makeText(parent, "An error occured " + e.toString(), Toast.LENGTH_LONG).show(); }
		parent.finish();
	}
	
	public static void returnToPresentation(Activity parent){
		Intent intent = new Intent(parent, Presentation.class);
		intent.putExtra("backAnimation", _animationList[2]);
		parent.startActivity(intent);
		try
        {
                ActivityAnimator anim = new ActivityAnimator();
                anim.getClass().getMethod(_animationList[2] + "Animation", Activity.class).invoke(anim, parent);
        }
		catch (Exception e) { Toast.makeText(parent, "An error occured " + e.toString(), Toast.LENGTH_LONG).show(); }
		parent.finish();
	}
	
	public static void goToFavs(Activity parent){
		Intent intent = new Intent(parent, Favourites.class);
		intent.putExtra("backAnimation", _animationList[1]);
		parent.startActivity(intent);
		try
        {
                ActivityAnimator anim = new ActivityAnimator();
                anim.getClass().getMethod(_animationList[1] + "Animation", Activity.class).invoke(anim, parent);
        }
		catch (Exception e) { Toast.makeText(parent, "An error occured " + e.toString(), Toast.LENGTH_LONG).show(); }
		parent.finish();
	}
	
	public static void goToMap(Activity parent){
		//Probably not necessary
		Intent intent = new Intent(parent, Map.class);
		intent.putExtra("backAnimation", _animationList[5]);
		parent.startActivity(intent);
		try
        {
                ActivityAnimator anim = new ActivityAnimator();
                anim.getClass().getMethod(_animationList[5] + "Animation", Activity.class).invoke(anim, parent);
        }
		catch (Exception e) { Toast.makeText(parent, "An error occured " + e.toString(), Toast.LENGTH_LONG).show(); }
		parent.finish();
	}
	
	public static void goToMap(Activity parent, Intent intent){		
		parent.startActivity(intent);
		parent.finish();
	}

	public static void goToSettings(Activity parent) {
		Intent intent = new Intent(parent, SettingsActivity.class);
		intent.putExtra("backAnimation", _animationList[5]);
		parent.startActivity(intent);
		try
        {
                ActivityAnimator anim = new ActivityAnimator();
                anim.getClass().getMethod(_animationList[5] + "Animation", Activity.class).invoke(anim, parent);
        }
		catch (Exception e) { Toast.makeText(parent, "An error occured " + e.toString(), Toast.LENGTH_LONG).show(); }
		parent.finish();
	}
	
	public static void goToFavMap(Activity parent){
		Intent intent = new Intent(parent, FavMapActivity.class);
		intent.putExtra("backAnimation", _animationList[4]);
		parent.startActivity(intent);
		try
        {
                ActivityAnimator anim = new ActivityAnimator();
                anim.getClass().getMethod(_animationList[4] + "Animation", Activity.class).invoke(anim, parent);
        }
		catch (Exception e) { Toast.makeText(parent, "An error occured " + e.toString(), Toast.LENGTH_LONG).show(); }
		parent.finish();
	}

	public static void goToPiso(Activity parent) {
		Intent itnt = new Intent(parent, PisoActivity.class);
		itnt.putExtra("backAnimation", _animationList[6]);
		parent.startActivity(itnt);
		try
        {
                ActivityAnimator anim = new ActivityAnimator();
                anim.getClass().getMethod(_animationList[6] + "Animation", Activity.class).invoke(anim, parent);
        }
		catch (Exception e) { Toast.makeText(parent, "An error occured " + e.toString(), Toast.LENGTH_LONG).show(); }
		parent.finish();
	}

	public static void goToParkingLot(Activity parent) {
		Intent itnt = new Intent(parent, Parking_lot.class);
		itnt.putExtra("backAnimation", _animationList[7]);
		parent.startActivity(itnt);
		try
        {
                ActivityAnimator anim = new ActivityAnimator();
                anim.getClass().getMethod(_animationList[7] + "Animation", Activity.class).invoke(anim, parent);
        }
		catch (Exception e) { Toast.makeText(parent, "An error occured " + e.toString(), Toast.LENGTH_LONG).show(); }
		parent.finish();
	}

	public static void goToDetalleLugar(Activity parent, String nombre) {
		Intent itnt = new Intent(parent, DetalleLugarActivity.class);
		itnt.putExtra("Nombre", nombre);
		//itnt.putExtra("backAnimation", _animationList[4]);
		parent.startActivity(itnt);
		try
        {
                ActivityAnimator anim = new ActivityAnimator();
                anim.getClass().getMethod(_animationList[2] + "Animation", Activity.class).invoke(anim, parent);
        }
		catch (Exception e) { Toast.makeText(parent, "An error occured " + e.toString(), Toast.LENGTH_LONG).show(); }
		parent.finish();
	}

	public static void guessNextMove(Activity act, String target) 
	{
		if (target.equals("System exit"))
		{
			Intent intent = new Intent(act, Presentation.class);
		    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		    intent.putExtra("Exit me", true);
		    act.startActivity(intent);
			act.finish();
		}	/*	
		if (target.equals("Back to main"))
		{
			goToMap(act);
		}
		if (target.equals("Log out"))
		{
			SQLiteDatabase db = DBManager.getInstance(act);
			db.execSQL("DELETE FROM Usuario;");
			db.close();
			goToMainView(act);
		}*/
	}
}
